//处理menuList的数据类型
interface menuState {
    menuList: Array<Object>
};
//引入menuList列表接口
import { menulist } from "../../request/api";
//引入消息提示
import { ElMessage } from "element-plus";

//数据仓库
const state = {
    menuList: [],//menu页的初始数组
};
//getters 处理数据
const getters = {
    //返回处理好的menuList数据
    getMenulist(state: menuState) {
        return state.menuList;
    }
};
//唯一修改state仓库的方法 mutations
const mutations = {
    //修改menuList方法
    REQ_MENU(state: menuState, payload: any) {
        state.menuList = payload;
    }
};
//处理异步操作的 axtions
const actions = {
    //获取menu列表方法
    async changeMenuAction({ commit }: any) {
        let res: any = await menulist();
        //判断是否获取成功
        if (res.code == 200) {
            //传输数据
            commit('REQ_MENU', res.list);
        } else {
            ElMessage.error(res.msg);
        }
    }
};



export default {
    state, getters, mutations, actions,
    namespaced: true
}